﻿namespace Chain.IDAL
{
    using Chain.DBUtility;
    using Chain.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;

    public class WxRedPacketsList
    {
        public int Add(Chain.Model.WxRedPacketsList model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into WxRedPacketsList(");
            builder.Append("money,SerialNumber,datetime,memid,state,msg,type,openid,status)");
            builder.Append(" values (");
            builder.Append("@money,@SerialNumber,@datetime,@memid,@state,@msg,@type,@openid,@status)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@money", SqlDbType.Money, 8)
                , new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 50)
                , new SqlParameter("@datetime", SqlDbType.DateTime)
            , new SqlParameter("@memid", SqlDbType.Int, 4),
            new SqlParameter("@state", SqlDbType.Int, 4)
            , new SqlParameter("@msg", SqlDbType.NVarChar, 50)
            , new SqlParameter("@type", SqlDbType.NVarChar, 50)
            , new SqlParameter("@openid", SqlDbType.NVarChar, 50)
            , new SqlParameter("@status", SqlDbType.NVarChar, 50)};
            cmdParms[0].Value = model.money;
            cmdParms[1].Value = model.SerialNumber;
            cmdParms[2].Value = model.datetime;
            cmdParms[3].Value = model.memid;
            cmdParms[4].Value = model.state;
            cmdParms[5].Value = model.msg;
            cmdParms[6].Value = model.type;
            cmdParms[7].Value = model.openid;
            cmdParms[8].Value = model.status;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

    }
}

